package com.tianji.coupon.controller;


import com.tianji.common.Result;
import com.tianji.coupon.service.UserCouponService;
import com.tianji.coupon.vo.CouponVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户领取优惠券的记录，是真正使用的优惠券信息 前端控制器
 * </p>
 *
 * @author 陈佳
 * @since 2024-09-11
 */
@RestController
@RequestMapping("/userCoupon")
@RequiredArgsConstructor
@Api(tags = "用户优惠券相关接口")
public class UserCouponController {

   private final UserCouponService userCouponService;

    @ApiOperation("查询发放中的优惠券列表")
    @GetMapping("/list")
    public Result queryIssuingCoupons(){
        return Result.success(userCouponService.queryIssuingCoupons());
    }

    @ApiOperation("领取优惠券接口")
    @PostMapping("/{couponId}/receive")
    public void receiveCoupon(@PathVariable("couponId") Long couponId){
        userCouponService.receiveCoupon(couponId);
    }

    @ApiOperation("兑换码兑换优惠券接口")
    @PostMapping("/{code}/exchange")
    public void exchangeCoupon(@PathVariable("code") String code){
        userCouponService.exchangeCoupon(code);
    }

    @ApiOperation("查询我的优惠券")
    @GetMapping("/user-coupons/page")
    public Result pageList(@RequestParam("page")Integer page,
                           @RequestParam("pageSize")Integer pageSize,
                           @RequestParam("status")Integer status){
        return Result.success(userCouponService.pageList(page,pageSize,status));
    }
}

